var e = getApp();

Page({
    data: {
        show: !1,
        imageurl: "",
        size: 0,
        ad: {}
    },
    chooseImage: function() {
        var e = this;
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album" ],
            success: async function(o) {
                let imgData = await getApp().checkImg(o.tempFilePaths[0])
                console.log(imgData)
                if(!imgData||imgData.result.errCode!==0){
                    wx.showModal({
                    confirmText: '确定',
                    content: '图片内容不合法，请重新选择',
                    showCancel: false
                    })
                    return
                }
                var n = o.tempFilePaths, t = new Number(o.tempFiles[0].size / 1024);
                e.setData({
                    imageurl: n,
                    show: !0,
                    size: t.toFixed(2) + "KB"
                }), e.save(n[0]);
            }
        });
    },
    save: function(e) {
        wx.showLoading({
            title: "正在保存图片"
        }), console.log(e), wx.saveImageToPhotosAlbum({
            filePath: e,
            success: function(e) {
                wx.hideLoading({
                    complete: function(e) {
                        wx.showToast({
                            title: "保存成功"
                        });
                    }
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    preview: function() {
        wx.previewImage({
            urls: this.data.imageurl
        });
    },
    onShow(){
        this.setData({
            ad: ''
        });
        this.setData({
            ad: getApp().globalData.selfAd[parseInt(getApp().globalData.selfAd.length*Math.random())]
        });
    },
    onLoad: function(o) {
       
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: "图片压缩-图片编辑助手",
            path: "pages/imagepress/imagepress"
        };
    }
});